package com.zebra.base.po;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * @ClassName BaseEnetity
 * @Description TODO 用于Po层
 * @Author 消魂钉
 * @Date 5/26 0026 14:55
 */
@Data
public class BaseEntity implements Serializable {

    /**
     * 删除标记（0：正常；1：删除；2：审核；）
     */
    public static final Integer DEL_FLAG_NORMAL = 0;
    public static final Integer DEL_FLAG_DELETE = 1;
    public static final Integer DEL_FLAG_AUDIT = 2;
    /**
     * 雪花算法（SnowFlake）是 Twitter 开源的分布式 id 生成算法。
     * 其核心思想就是：使用一个 64 bit 的 long 型的数字作为全局唯一 id。在分布式系统中的应用十分广泛，且 ID 引入了时间戳，基本上保持自增的。
     */
    @ApiModelProperty(value = "主键:雪花算法")
    @TableId(value="id",type = IdType.ASSIGN_ID)
    private String id;

    @ApiModelProperty(value = "创建人")
    @TableField(value="create_by",fill = FieldFill.INSERT)
    private String createBy;

    @ApiModelProperty(value = "创建时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value="create_date",fill = FieldFill.INSERT)
    private Date createDate;

    @ApiModelProperty(value = "修改人")
    @TableField(value="update_by",fill = FieldFill.INSERT_UPDATE)
    private String updateBy;

    @ApiModelProperty(value = "主键")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value="update_date",fill = FieldFill.INSERT_UPDATE)
    private Date updateDate;

    @ApiModelProperty(value = "主键")
    @TableField(value="remarks")
    private String remarks;

    @ApiModelProperty(value = "主键")
    @Builder.Default
    @TableLogic
    @TableField(value="del_flag")
    private Integer delFlag;
    /**
     * 乐观锁
     */
    @Version
    @TableField(value="version")
    private Integer version;


    public BaseEntity() {
    }

    public BaseEntity(String id, String createBy,
                      Date createDate, String updateBy,
                      Date updateDate, String remarks,
                      Integer delFlag) {
        this.id = id;
        this.createBy = createBy;
        this.createDate = createDate;
        this.updateBy = updateBy;
        this.updateDate = updateDate;
        this.remarks = remarks;
        this.delFlag = delFlag;
    }
}
